Imports System.Xml.XPath

'<Obsolete()> _
'Public Class SearchFieldFormatterFactory

'    Private Sub New()


'    End Sub


'    Public Shared Function GetSearchFieldFormatter(ByVal dbName As String, ByVal fieldName As String) As ISearchFieldFormatter
'        Dim listDoc As XPathDocument
'        Dim listNavigator As XPathNavigator

'        listDoc = New XPathDocument(My.Settings.DatabaseConfigXPath)

'        listNavigator = listDoc.CreateNavigator

'        Dim dbXPath As String

'        dbXPath = String.Format(My.Settings.DatabaseXPath, dbName)

'        Dim databaseNode As XPathNavigator

'        Try

'            databaseNode = listNavigator.SelectSingleNode(dbXPath)

'        Catch ex As Exception

'            databaseNode = Nothing

'        End Try

'        Dim formatter As ISearchFieldFormatter = CreateSearchFieldFormatter(databaseNode, fieldName)

'        Return formatter

'    End Function

'#Region "Search Formatter Methods"

'    ''' <summary>
'    ''' 
'    ''' </summary>
'    ''' <param name="dbNode"></param>
'    ''' <returns></returns>
'    ''' <remarks></remarks>
'    Private Shared Function CreateSearchFieldFormatter(ByVal dbNode As XPathNavigator, ByVal fieldName As String) As ISearchFieldFormatter

'        Dim formatter As ISearchFieldFormatter = New NullSearchFieldFormatter()

'        Try

'            If dbNode IsNot Nothing Then

'                Dim fieldInfo As New SearchFieldInfo

'                Dim filePath As String = dbNode.SelectSingleNode("Config").SelectSingleNode("FormatterFile").GetAttribute("Name", String.Empty)

'                Dim typeName As String = dbNode.SelectSingleNode("Config").SelectSingleNode("Formatter").GetAttribute("Name", String.Empty)

'                If String.IsNullOrEmpty(filePath) AndAlso Not String.IsNullOrEmpty(typeName) Then

'                    formatter = DirectCast(Activator.CreateInstance _
'                        (Type.GetType(typeName)), ISearchFieldFormatter)

'                ElseIf Not String.IsNullOrEmpty(filePath) AndAlso Not String.IsNullOrEmpty(typeName) Then

'                    formatter = DirectCast(Activator.CreateInstanceFrom _
'                        (filePath, typeName), ISearchFieldFormatter)

'                Else 'Field Not Found

'                    formatter = New NullSearchFieldFormatter

'                End If

'                PopulateFieldInfo(fieldInfo, GetFieldNavigator(dbNode, fieldName))

'                formatter.SearchField = fieldInfo

'            Else 'Database Not Found

'                Throw New InvalidOperationException("Database configuration not found, defaults were loaded.")

'            End If


'        Catch ex As Exception

'            formatter = New NullSearchFieldFormatter
'            formatter.SearchField = New SearchFieldInfo()


'        End Try

'        Return formatter

'    End Function



'    Private Shared Sub PopulateFieldInfo(ByVal info As ISearchFieldInfo, ByVal fieldNav As XPathNavigator)

'        If fieldNav IsNot Nothing Then

'            info.Name = fieldNav.GetAttribute("Name", String.Empty)

'            info.Tag = fieldNav.GetAttribute("Tag", String.Empty)

'            info.Description = fieldNav.GetAttribute("Description", String.Empty)

'        End If

'    End Sub


'    Private Shared Function GetFieldNavigator(ByVal dbNode As XPathNavigator, ByVal fieldName As String) As XPathNavigator

'        Dim fieldNav As XPathNavigator = Nothing

'        If dbNode IsNot Nothing Then


'            Try

'                fieldNav = dbNode.SelectSingleNode _
'                    (String.Format(My.Settings.FieldXPath, dbNode.GetAttribute("Id", String.Empty), fieldName))

'                If fieldNav Is Nothing Then

'                    fieldNav = dbNode.SelectSingleNode(String.Format _
'                        (My.Settings.FieldXPath, dbNode.GetAttribute("Id", String.Empty), dbNode.GetAttribute("DefaultField", String.Empty)))

'                End If

'            Catch xPathEx As System.Xml.XPath.XPathException ' The XPath query is not valid.
'                Return Nothing


'            Catch argEx As System.ArgumentException 'An error was encountered in the XPath query or the return type of the XPath expression is not a node.
'                Return Nothing

'            Catch ex As Exception
'                Return Nothing

'            End Try

'        End If

'        Return fieldNav

'    End Function


'#End Region

'End Class
